<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
	<script>var ctx="${ctx}";</script>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <title>会员管理</title>
	    <meta name="keywords" content="体验,友好,高级管理台,易用,高性能,高扩展性,bootstrap框架,响应式后台">
	    <meta name="description" content="这是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
	    <meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
		<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT"> 
	    
		<link rel="shortcut icon" href="favicon.ico"> 
		<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/footable/footable.core.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote-bs3.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/plugins/laypage/laypage.css?v=${static_version}"  rel="stylesheet">
		<link href="${ctx}/static/css/plugins/iCheck/custom.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/chosen/chosen.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/animate.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/webuploader/webuploader.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/style.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/switchery/switchery.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/layer/laydate/laydate.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/uploadify/uploadify.css?v=${static_version}/" rel="stylesheet">
		
	    
	</head>
	<body class="gray-bg">
    	<div class="ibox float-e-margins">
    		<div class="ibox-content">
                <form class="form-group" id="member_table_form">	
                	<input type="hidden" name="orderBy" value="create_date desc">
                	<input type="hidden" id="member-select-id" name="member-select" value="">
                	<div class="row">
                		<perm:hasPermission code="member/find">
                        <div class="col-md-2"><input name="keyword" type="text" placeholder="请输入昵称或姓名" class="form-control" /></div>
		     	  		<div class="col-md-4">
                            <div class="input-daterange input-group">
                                <input id="startTime" type="text" class="input-md form-control layer-date" placeholder="开始时间"  name="startTime">
					        	<span class="input-group-addon">至</span>
					        	<input id="endTime" type="text" class="input-md form-control layer-date" placeholder="结束时间"  name="endTime">
                            </div>
					    </div>
						<div class="col-md-1 col-sm-2">
							<button id="member_table_search" type="button" class="btn btn-outline btn-block btn-primary">查询</button>
						</div>
						</perm:hasPermission>
						<perm:hasPermission code="member/insertGet">
					    <div class="col-md-1  col-sm-2 pull-right " style="display: none">
							<a  onclick="clickInsertGet()" class="btn btn-block btn-outline btn-primary">添加</a>
					    </div>
					    </perm:hasPermission>
                    </div>
                </form>
				<table id="member_table" data-action="${ctx}/member/find" data-datatable="true"  class="footable table table-stripped toggle-arrow-tiny">
				  	<thead>
					  	<tr>
					  		<th  data-sort-ignore="true" data-title ="headImage" data-hide="phone,tablet" data-type="callback" data-callback="initUserImage">头像</th>
							<th data-sort-ignore="true"  data-title="nickName" >昵称</th>
							<th data-sort-ignore="true"  data-title="name" >姓名</th>
							<th data-sort-ignore="true"  data-title="gender"  data-type="enum" data-opt='{"1":"男","2":"女"}'>性别</th>
							<th data-sort-ignore="true"  data-title="mobile" >手机号</th>
							<th data-sort-ignore="true"  data-title="enabled"  data-type="enum" data-opt='{"0":"启用","1":"禁用"}'>状态</th>
							<th data-sort-ignore="true"  data-title="isMerchant"  data-type="enum" data-opt='{"0":"否","1":"是"}'>商家</th>
							<th data-sort-ignore="true"  data-title="createDate" data-type="datetime" data-formater="yyyy-MM-dd" data-hide="phone,tablet">创建时间</th><perm:hasPermission code="member/upEnabled">
							<th data-sort-ignore="true"  data-crud="true" data-title='{"uid":"id"}' data-hide="phone">密码重置
			      			  <div style="display: none;" class="center hidden-phone">
										<div class="btn-group">
				                            <a data-toggle="dropdown" class="dropdown-toggle" href="#" aria-expanded="false">
				                                <span class="clear">
				                                <span class="btn btn-xs btn-outline btn-success"><i class="fa fa-cog"></i>&nbsp;操作<b class="caret"></b></span>
				                                </span>
				                            </a>
				                            
				                            <ul class="dropdown-menu animated fadeInRight m-t-xs">
				                                	<li><a onclick="resetPassword(this)" data-id=":uid" type="button">重置登录密码</a></li>
				                                <li class="divider"></li>
				                                	<li><a onclick="resetPayword(this)" data-id=":uid" type="button">重置支付密码</a></li>
				                            </ul>
				                        </div>
							  </div> 
		      		      	</th>
				            </perm:hasPermission>
							<th data-sort-ignore="true"  data-crudx="true" data-title='{"uid":"id"}' data-hide="phone">操作
			      			  <div style="display: none;" class="center hidden-phone">
											  	<perm:hasPermission code="member/enableStatus">
						      			  			<button data-type='change' data-toge="enabled"  data-callback="enableStatus" data-id=":uid" style="margin-left:3px;margin-top:3px" type="button" class="btn btn-outline btn-success btn-xs"><i class="fa fa-unlock-alt"></i>&nbsp;启用/禁用</button>
										  		</perm:hasPermission>
							      			  	 <perm:hasPermission code="member/updateGet">
							      			  	 	<button onclick="clickUpdateGet(this)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-info btn-xs"><i class="fa fa-pencil"></i>&nbsp;更新</button>
							      			  	 </perm:hasPermission><br>
							  </div> 
		      		      	</th>
					  	</tr>
				  	</thead>
				  	<tbody>
				  	</tbody>
			  	</table>
			  	<div class="row">
			  		<div class="col-md-6" class="pull-left" id="page_left_text"></div>
			  		<div class="col-md-6"  id="page_text"></div>
			  	</div>
			</div>
		</div>
		
	<script src="${ctx}/static/js/jquery.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/footable/footable.all.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/jquery.validate.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/messages_zh.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/webuploader/webuploader.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote-zh-CN.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/chosen/chosen.jquery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/plugins/laypage/laypage.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/switchery/switchery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/eModal.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/cookie.js?v=?v=${static_version}"></script>
	<script src="${ctx}/static/common/custom-datatable.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/content.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/common/common.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/laydate/laydate.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/uploadify/jquery.uploadify.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/content.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/layer.js?v=${static_version}"></script>
	
	
	
	<script>
		

	
	var enableStatus=function(cData,cLable,row,togeColumn){
		console.log("---["+JSON.stringify(togeColumn)+"]");
		if(togeColumn["enabled"]===1){
			return '<button onclick="clickChangeStatus(this,0)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-success btn-xs"><i class="fa fa-unlock-alt"></i>&nbsp;启用</button>';
		}else{
			return '<button onclick="clickChangeStatus(this,1)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-success btn-xs"><i class="fa fa-unlock-alt"></i>&nbsp;禁用</button>';
		}
	}
	
	var clickChangeStatus=function(me,enabled){
		var text="确定禁用用户?";
		 if(status===0){
			 text="确定启用用户?";
		 }
		 $.confirm({
		    text:text,
		    confirm: function() {
		    	$.ajax({  
		    		url:'${ctx}/member/upEnabled',  
   					data:{
   						id:$(me).data("id"),
   						enabled:enabled
   					},   
					type: 'POST',
	 					dataType:'json',  
	 					success:function(response){
	 						if(response.code==0){
	 							eModal.close();
	 							$("#member_table_search").click();
	 						}else{
	 						    $.confirm({cancelButton: "关   闭",title: '提示',text:"重置用户密码错误!"});
	 						}
	 					}  
	 			    });  
		    },
		    cancel: function() {
		        return true;
		    }
		});
	}

		$(document).ready(function() {
			init_page_datatable();
		});

		var resetPassword=function(me){
			$.confirm({
			    text:"确定重置用户登录密码?重置后密码为123456!",
			    confirm: function() {
			    	$.ajax({  
	   	 		    	url:'${ctx}/member/resetPassword',  
	   					data:{
	   						password:123456,
	   						id:$(me).data("id")
	   					},   
						type: 'POST',
   	 					dataType:'json',  
   	 					success:function(response){
   	 						if(response.code==0){
   	 							eModal.close();
   	 						}else{
   	 						    $.confirm({cancelButton: "关   闭",title: '提示!',content:"重置用户密码错误!"});
   	 						}
   	 					}  
   	 			    });  
			    },
			    cancel: function() {
			        return true;
			    }
			});
		}
		var resetPayword=function(me){
			$.confirm({
			    text:"确定重置用户支付密码?重置后密码为123456!",
			    confirm: function() {
			    	$.ajax({  
	   	 		    	url:'${ctx}/member/resetPayword',  
	   					data:{
	   						payword:123456,
	   						id:$(me).data("id")
	   					},   
						type: 'POST',
   	 					dataType:'json',  
   	 					success:function(response){
   	 						if(response.code==0){
   	 							eModal.close();
   	 						}else{
   	 						    $.confirm({cancelButton: "关   闭",title: '提示!',content:"重置用户密码错误!"});
   	 						}
   	 					}  
   	 			    });  
			    },
			    cancel: function() {
			        return true;
			    }
			});
		}
		var clickUpdateGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/member/updateGet?id="+$(me).data("id"),
	   	        title:'修改会员',
	   	        loading:true,
	   	        subtitle: '',
	   	        buttons: [
	   	            {text:'保存',style:'info',close:false,click:function(){
	   	            	if (!jQuery.checkall(true)) return;
		   	     		var images=[];
		   	     		var licimages=[];
		   	 			$("#logodiv img").each(function(){
		   					images.push($(this).attr("src"));
		   				})
		   				$("#licensediv .upimg").each(function(){
		   					licimages.push($(this).attr("src"));
		   				})
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/member/update',  
	   	 					data:{
								gender:$("#gender").val(),							
								name:$("#name").val(),							
								nickName:$("#nickName").val(),									
								cardImage:licimages.toString(),				
								headImage:images.toString(),			
								typeId:$("typeId").val,
								token:$("#token").val(),	
								birthday:$("#saleTime").val()+" "+$("[name='saleTimeS']").val()+":00:00",				
// 								headImage:$("#headImage").val(),							
								mobile:$("#mobile").val(),							
								account:$("#account").val(),							
								password:$("#password").val(),							
								payword:$("#payword").val(),							
								cardNo:$("#cardNo").val(),							
// 								cardImage:$("#cardImage").val(),							
								thirdId:$("#thirdId").val(),							
								thirdName:$("#thirdName").val(),	
								gender:$("[name='enabled']").is(":checked")?0:1,							
								type:$("#type").val(),							
								isMerchant:$("#isMerchant").val(),							
								updateDate:$("#updateDate").val(),							
								createDate:$("#createDate").val(),							
								provinceId:$("#provinceId").val(),							
								cityId:$("#cityId").val(),							
								province:$("#province").val(),							
								city:$("#city").val(),							
								id:$("#id").val()
							},   
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#member_table_search").click();
	   	 						}else if(response.message==1){
		 							  layer.msg('该手机号已被注册！', {icon: 5});
	   	 						}else if(response.message==2){
		 							  layer.msg('该昵称已存在！', {icon: 5});
		 						}else if(response.message==3){
		 							  layer.msg('该身份证已在本平台绑定过账号！', {icon: 5});
		 						}
	   	 						else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示!',content: "修改会员错误!"});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
		}
		
// 		var clickInsertGet=function(){
// 			eModal.ajax({
// 	   	        url: "${ctx}/member/insertGet",
// 	   	        title:'添加会员',
// 	   	        loading:true,
// 	   	        subtitle: '',
// 	   	        buttons: [
// 	   	            {text: '保存',style:'info',close:false,click:function(){
// 		   	     		var images=[];
// 		   	     		var licimages=[];
// 		   	 			$("#logodiv img").each(function(){
// 		   					images.push($(this).attr("src"));
// 		   				})
// 		   				$("#licensediv img").each(function(){
// 		   					licimages.push($(this).attr("src"));
// 		   				})
// 	   	 		    	$.ajax({  
// 	   	 					url:'${ctx}/member/add',  
// 	   	 					data:{
// 								gender:$("#gender").val(),							
// 								name:$("#name").val(),							
// 								nickName:$("#nickName").val(),		
// // 								typeId:$("typeId").val,					
// // 								birthday:$("#saleTime").val(),		
// 								birthday:$("#saleTime").val()+" "+$("[name='saleTimeS']").val()+":00:00",											
// 								cardImage:licimages.toString(),				
// 								headImage:images.toString(),							
// 								mobile:$("#mobile").val(),			
// 								token:$("#token").val(),					
// 								account:$("#account").val(),							
// 								password:$("#password").val(),							
// 								payword:$("#payword").val(),							
// 								cardNo:$("#cardNo").val(),										
// 								thirdId:$("#thirdId").val(),							
// 								thirdName:$("#thirdName").val(),		
// 								gender:$("[name='enabled']").is(":checked")?0:1,						
// 								type:$("#type").val(),							
// 								isMerchant:$("#isMerchant").val(),							
// 								updateDate:$("#updateDate").val(),							
// 								createDate:$("#createDate").val(),							
// 								provinceId:$("#provinceId").val(),							
// 								cityId:$("#cityId").val(),							
// 								province:$("#province").val(),							
// 								city:$("#city").val(),							
// 								id:$("#id").val(),
// 								token:$("#token").val()
// 							},   
// 							type: 'POST',
// 	   	 					dataType:'json',  
// 	   	 					success:function(response){
// 	   	 						if(response.code==0){
// 	   	 							eModal.close();
// 	   	 							$("#member_table_search").click();
// 	   	 						}else{
// 	   	 						    $.confirm({cancelButton: "关   闭",title: '提示!',content:"添加会员错误!"});
// 	   	 						}
// 	   	 					}  
// 	   	 			    }); 
// 	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
// 	   	            	eModal.close();
// 	   	            }}
// 	   	        ],
// 	   	    });
// 		}
		
		var initUserImage=function(cData,cLable,row){
			if(cData!=null&&cData!=""){
				return '<img alt="image" class="img-circle message-avatar" src="'+cData+'">';
			}else{
				return '未上传';
			}
		}
		
		
	</script>
	
</html>